package models

import (
	"time"

	"github.com/astaxie/beego/orm"
)

type IpccAppChangeStatus struct {
	Id           int
	UpdateStatus int
	Describ      string
	UpdateTime   time.Time
}

func GetChangeStatus() (IpccAppChangeStatus, error) {
	status := IpccAppChangeStatus{Id: 1}

	o := orm.NewOrm()
	o.Using("default")

	err := o.Read(&status)
	return status, err
}

func UpdateStatus() error {

	status := IpccAppChangeStatus{Id: 1,
		UpdateTime: time.Now()}

	o := orm.NewOrm()
	o.Using("default")

	_, err := o.Update(&status, "UpdateTime")
	return err
}

func GetTTSChangeStatus() (IpccAppChangeStatus, error) {
	status := IpccAppChangeStatus{Id: 2}

	o := orm.NewOrm()
	o.Using("default")

	err := o.Read(&status)

	return status, err
}

func UpdateTTSStatus(ttsInfo string) error {

	status := IpccAppChangeStatus{
		Id:         2,
		Describ:    ttsInfo,
		UpdateTime: time.Now()}

	o := orm.NewOrm()
	o.Using("default")

	_, err := o.Update(&status, "Describ", "UpdateTime")
	return err
}

func GetAsrDelay() (IpccAppChangeStatus, error) {
	status := IpccAppChangeStatus{Id: 3}

	o := orm.NewOrm()
	o.Using("default")

	err := o.Read(&status)
	return status, err
}

func UpdateAsrDelay(delay int) error {

	status := IpccAppChangeStatus{Id: 3,
		UpdateStatus: delay,
		UpdateTime:   time.Now()}

	o := orm.NewOrm()
	o.Using("default")

	_, err := o.Update(&status, "UpdateTime", "UpdateStatus")
	return err
}

func GetTransferNumber() (IpccAppChangeStatus, error) {
	status := IpccAppChangeStatus{Id: 4}

	o := orm.NewOrm()
	o.Using("default")

	err := o.Read(&status)
	return status, err
}

func GetDisplayNumber() (IpccAppChangeStatus, error) {
	status := IpccAppChangeStatus{Id: 5}

	o := orm.NewOrm()
	o.Using("default")

	err := o.Read(&status)
	return status, err
}

func RegIpccAppChangeStatus() {
	orm.RegisterModel(new(IpccAppChangeStatus))
}
